<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Event;//使用的是门面
use App\Events\EventTest;

class RegisterController extends Controller
{
    public function index()
    {
        return view('register/index');
    }

    public function register()
    {
        $this->validate(request(),[
            'name' => 'required|min:3|unique:users,name',
            'email' => 'required|unique:users,email|email',//邮箱格式
            'password' => 'required|min:1|confirmed',
        ]);

        $password = bcrypt(request('password'));
        $name = request('name');
        $email = request('email');
        $user = User::create(compact('name', 'email', 'password'));

        $user = User::find(31);
        // file_put_contents('c:/123/123.txt',var_export(111 ,true),FILE_APPEND);
        Event::fire(new EventTest($user,3456));
        // file_put_contents('c:/123/123.txt',var_export(222 ,true),FILE_APPEND);
        return redirect('/login');
    }
}
